/**
 * @author https://vue-admin-beautiful.com （不想保留author可删除）
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'
import PermissionType from '@/utils/PermissionType'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
  {
    path: '/weixin',
    component: () => import('@/views/weixin'),
    hidden: true
  },
  {
    path: '/wxcode',
    component: () => import('@/views/wxcode'),
    hidden: true
  },
  {
    path: '/',
    name: 'index',
    component: () => import('@/views/index/index'),
    hidden: true,
  },

  /*通过点击按钮打开 tabsBar 快捷导航*/
  {
    path: '/publicnav',
    component: Layout,
    redirect: 'noRedirect',
    name: 'PublicNav',
    hidden: true,
    children: [
      {
        path: 'orderinfo',
        name: 'Emp_OrderInfo',
        component: () => import('@/views/emp/orderinfo'),
        meta: { title: 'Order Info', icon: 'box', permissions: [PermissionType.yuanGong, PermissionType.keHu]  },
      },
      {
        path: 'orderlogistics',
        name: 'Emp_OrderLogistics',
        component: () => import('@/views/emp/orderlogistics'),
        meta: { title: 'Order Logistics', icon: 'box', permissions: [PermissionType.yuanGong]  },
      },
    ],
  },
]

export const asyncRoutes = [
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/index',
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Index',
  //       component: () => import('@/views/index/index'),
  //       meta: {
  //         title: '首页',
  //         icon: 'home',
  //         affix: true,
  //       },
  //     },
  //   ],
  // },
  {
    path: '/emporder',
    component: Layout,
    redirect: 'noRedirect',
    name: 'EmpOrder',
    meta: { title: 'Order', icon: 'list-ul', permissions: [PermissionType.yuanGong]   },
    children: [
      {
        path: 'ordermgr',
        name: 'Emp_OrderMgr',
        component: () => import('@/views/emp/ordermgr'),
        meta: { title: 'Order Mamager', icon: 'book', permissions: [PermissionType.yuanGong]  },
      },
      {
        path: 'stepmodel',
        name: 'Emp_StepModel',
        component: () => import('@/views/emp/stepmodel/scstepmodel'),
        meta: { title: 'Product Step Model', icon: 'book', permissions: [PermissionType.yuanGong]  },
      },
    ],
  },
  {
    path: '/empuser',
    component: Layout,
    redirect: 'noRedirect',
    name: 'EmpUser',
    meta: { title: 'Custom Admin', icon: 'user-friends', permissions: [PermissionType.yuanGong]   },
    children: [
      {
        path: 'kehu',
        name: 'emp_kehu_kehu',
        component: () => import('@/views/emp/kehu/kehu'),
        meta: { title: 'Custom User', icon: 'user', permissions: [PermissionType.yuanGong]  },
      },
      {
        path: 'wluser',
        name: 'emp_wluser_wluser',
        component: () => import('@/views/emp/wluser/wluser'),
        meta: { title: 'Logistics User', icon: 'user', permissions: [PermissionType.yuanGong]  },
      },
    ],
  },

  {
    path: '/wluser',
    component: Layout,
    redirect: 'noRedirect',
    name: 'WlUser',
    meta: { title: 'Order', icon: 'list-ul', permissions: [PermissionType.wlUser]   },
    children: [
      {
        path: 'logistics',
        name: 'WlUser_Logistics',
        component: () => import('@/views/wluser/logistics'),
        meta: { title: 'Logistics List', icon: 'list-ul', permissions: [PermissionType.wlUser]  },
      },
    ],
  },
  {
    path: '/kehuorder',
    component: Layout,
    redirect: 'noRedirect',
    name: 'KeHuOrder',
    meta: { title: 'Order', icon: 'list-ul', permissions: [PermissionType.keHu]   },
    children: [
      {
        path: 'orderlist',
        name: 'KeHu_OrderList',
        component: () => import('@/views/kehu/orderlist'),
        meta: { title: 'Order List', icon: 'list-ul', permissions: [PermissionType.keHu]  },
      },
    ],
  },
  {
    path: '/kehupwd',
    component: Layout,
    redirect: 'noRedirect',
    name: 'KeHuPwd',
    meta: { title: 'Order', icon: 'list-ul', permissions: [PermissionType.keHu, PermissionType.wlUser]   },
    children: [
      {
        path: 'changepwd',
        name: 'kehu_ChangePwd',
        component: () => import('@/views/sys/user/changepwd'),
        meta: { title: 'Change password', icon: 'user-lock' },
      },
    ],
  },

  {
    path: '/sys',
    component: Layout,
    redirect: 'noRedirect',
    name: 'SysManagement',
    meta: { title: 'System', icon: 'tools', permissions: [PermissionType.sysAdmin] },
    children: [
      {
        path: 'user',
        name: 'sys_user_user',
        component: () => import('@/views/sys/user/user'),
        meta: { title: 'Internal Employees', icon: 'user' },
      },
      {
        path: 'loginlog',
        name: 'sys_loginlog',
        component: () => import('@/views/sys/loginlog/index'),
        meta: { title: 'Login log', icon: 'file-alt'  },
      },
    ],
  },

  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export function resetRouter() {
  location.reload()
}

export default router
